home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PORTABLE.ZIP / OVERWRIT.C < prev    next >
Text File  |  1992-11-21  |  3KB  |  103 lines

  1. #define        CURSES_LIBRARY  1
  2. #include <curses.h>
  3. #undef overwrite
  4.  
  5. #ifndef        NDEBUG
  6. char *rcsid_overwrit = "$Header: c:/curses/portable/RCS/overwrit.c%v 2.0 1992/11/15 03:29:36 MH Rel $";
  7. #endif
  8.  
  9.  
  10.  
  11.  
  12. /*man-start*********************************************************************
  13.  
  14.   overwrite()  - Overwrite windows
  15.  
  16.   X/Open Description:  overlay() and overwrite()
  17.        These functions overlay src_w on top of dst_w; that is,
  18.        all text in src_w is copied into dst_w. The windows
  19.        src_w and dst_w are not required to be the same size. The
  20.        copy starts at (0, 0) on each window. The difference between
  21.        the two functions is that overlay() is non-destructive
  22.        (blanks are not copied) while overwrite() is destructive
  23.        (blanks are copied).
  24.  
  25.   PDCurses Description:
  26.        No additional PDCurses functionality.
  27.  
  28.   X/Open Return Value:
  29.        The overwrite() function returns OK on success and ERR on error.
  30.  
  31.   PDCurses Errors:
  32.        It is an error to pass a NULL window pointer.
  33.  
  34.   Portability:
  35.        PDCurses        int     overwrite( WINDOW* src_w, WINDOW* dst_w );
  36.        X/Open Dec '88  int     overwrite( WINDOW* src_w, WINDOW* dst_w );
  37.        BSD Curses      int     overwrite( WINDOW* src_w, WINDOW* dst_w );
  38.        SYS V Curses    int     overwrite( WINDOW* src_w, WINDOW* dst_w );
  39.  
  40. **man-end**********************************************************************/
  41.  
  42. int    overwrite(WINDOW *src_w, WINDOW *dst_w)
  43. {
  44.        int*    minchng;
  45.        int*    maxchng;
  46.        chtype* w1ptr;
  47.        chtype* w2ptr;
  48.        chtype  attrs;
  49.        int     col;
  50.        int     line;
  51.        int     last_line;
  52.        int     last_col;
  53.  
  54.        if (src_w == (WINDOW *)NULL)    return( ERR );
  55.        if (dst_w == (WINDOW *)NULL)    return( ERR );
  56.  
  57.        minchng   = dst_w->_firstch;
  58.        maxchng   = dst_w->_lastch;
  59.        last_col  = min(src_w->_maxx, dst_w->_maxx) - 1;
  60.        last_line = min(src_w->_maxy, dst_w->_maxy) - 1;
  61.        attrs     = dst_w->_attrs;
  62.  
  63.        for (line = 0; line <= last_line; line++)
  64.        {
  65.                register int fc;
  66.                register int lc;
  67.  
  68.                w1ptr = src_w->_y[line];
  69.                w2ptr = dst_w->_y[line];
  70.                fc    = _NO_CHANGE;
  71.  
  72.                for (col = 0; col <= last_col; col++)
  73.                {
  74.                        if ((*w1ptr & A_CHARTEXT) != (*w2ptr & A_CHARTEXT))
  75.                        {
  76.                                *w2ptr = (*w1ptr & A_CHARTEXT) | attrs;
  77.                                if (fc == _NO_CHANGE)
  78.                                {
  79.                                        fc = col;
  80.                                }
  81.                                lc = col;
  82.                        }
  83.                        w1ptr++;
  84.                        w2ptr++;
  85.                }
  86.  
  87.                if (*minchng == _NO_CHANGE)
  88.                {
  89.                        *minchng = fc;
  90.                        *maxchng = lc;
  91.                }
  92.                else    if (fc != _NO_CHANGE)
  93.                {
  94.                        if (fc < *minchng)      *minchng = fc;
  95.                        if (lc > *maxchng)      *maxchng = lc;
  96.                }
  97.                minchng++;
  98.                maxchng++;
  99.        }
  100.        return( OK );
  101. }
  102.  
  103.